﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BLL.BusinessClasses;

namespace WebSite.Empresa
{
    public partial class VerEgresados : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["UsuarioDeSesion"] == null || !(this.Session["UsuarioDeSesion"] is UsuarioEmpresa))
            {
                this.Response.Redirect(@"~/General/Principal.aspx");
                return;
            }
            if (!(this.Page.IsPostBack))
            {
                this.DarBienvenida();
            } 
        }

        protected void Button_LogOff_Click(object sender, EventArgs e)
        {
            this.Session["UsuarioDeSesion"] = null;

            this.Response.Redirect(@"~/General/Principal.aspx");
        }

        private void DarBienvenida()
        {
            ((Label)(this.Master.FindControl("Label_Bienvenida"))).Text = "Bienvenido <u>" +
                                                                          ((UsuarioEmpresa)this.Session["UsuarioDeSesion"]).EmpresaProcedencia.Nombre + 
                                                                          "</u>";
        }

        protected object EvalEstado() 
        {            
            switch (Eval("Estado").ToString().Trim())
            {
                case "Activo":
                    return "Empleado";
                    break;
                case "Inactivo":
                    return "Desempleado";
                    break;
                case "Incognito":
                    return "No Especificado";
                    break;
                default:
                    return "No Especificado";
                    break;
            }
        }

        protected void BindPictures(GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {              
                if (((string)DataBinder.Eval(e.Row.DataItem, "Foto")) != null)
                {
                    ((Image)e.Row.FindControl("Image_Foto")).ImageUrl = ((string)DataBinder.Eval(e.Row.DataItem, "Foto"));
                }
                else
                {
                    if ((DataBinder.Eval(e.Row.DataItem, "Sexo")).ToString() == "M")
                        ((Image)e.Row.FindControl("Image_Foto")).ImageUrl = "~\\Pictures\\UserPictures\\DefaultMUserPic.png";
                    else if ((DataBinder.Eval(e.Row.DataItem, "Sexo")).ToString() == "F")
                        ((Image)e.Row.FindControl("Image_Foto")).ImageUrl = "~\\Pictures\\UserPictures\\DefaultFUserPic.png";
                }
            }   
        }

        protected void GridView_Estudiantes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            this.BindPictures(e);
        }

        protected void GridView_Egresados_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //((PlaceHolder)e.Row.FindControl("PlaceHolder_Carreras")).
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((ListBox)e.Row.FindControl("ListBox_Carreras")).DataSource = Carrera.GetCarrerasByUsuarioEgresadoID(Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID").ToString()));

                ((ListBox)e.Row.FindControl("ListBox_Carreras")).DataTextField = "Descripcion";
                
                ((ListBox)e.Row.FindControl("ListBox_Carreras")).DataBind();
            }
            
            this.BindPictures(e);
        }
    }
}
